<template>
  <div class="app-container">
    <div class="head-container">
      <customBtns :permission="permission" :route-path="routePath" />
      
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="sitename" label="名称" />
        <el-table-column prop="sitecode" label="编码" />
        <el-table-column prop="position" label="位置" />
        <el-table-column prop="manager" label="负责人" />
        <el-table-column prop="phone" label="联系电话" />
        <el-table-column prop="email" label="邮箱" />
        <el-table-column prop="sortName" label="排序" />
        <el-table-column v-permission="['admin','']" label="操作" width="180px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
              :customRowBtnObj="customRowBtnObj"
              @customMethod="test"
            />
          </template>
        </el-table-column>
      </el-table>
      <pagination />
    </div>
  </div>
</template>

<script>
import crudIotSite from '@/api/iot/iotSite'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import customBtns from "@crud/customBtns";
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import customOperation from "@crud/customOperation"
import pagination from '@crud/Pagination'
import selectSite from './selectSite'


const defaultForm = { id: null, sitename: null, sitecode: null, imgfile: null, position: null, manager: null, phone: null, email: null, sort: null, createtime: null, updatetime: null }
export default {
  name: 'IotSite',
  components: { pagination, crudOperation, rrOperation, udOperation, customBtns, customOperation, selectSite},
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ 
                  title: '场地', 
                  url: 'iot/site', 
                  sort: 'sortName,asc', 
                  crudMethod: { ...crudIotSite }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'iotSite:add', ''],
        edit: ['admin', 'iotSite:edit', ''],
        del: ['admin', 'iotSite:del', '']
      },
      routePath: {
        add: "/iot/siteSave",
        edit: "/iot/siteSave",
        PK_FIELD: "id"
      },      
      customRowBtnObj: {
        icon: "el-icon-document",
        name: "查看"
      },
      rules: {
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    [CRUD.HOOK.beforeToEdit](crud, form) {
      const query = {}
      query._PK_ = form.id
      query.id = form.id
      this.$router.push({
        path: "/iot/siteSave",
        query
      })
    },
    test(data) {
      const query = {}
      query._PK_ = data.id
      this.$router.push({
        path: "/iot/siteSave",
        query
      })
    }

  }
}
</script>

<style scoped>

</style>
